function showTime(d){
	
	//to show day of week in zhongwen
	function showDayOfWeek(d) {
		var weekday = new Array(7);
		weekday[0] = "星期日";
		weekday[1] = "星期一";
		weekday[2] = "星期二";
		weekday[3] = "星期三";
		weekday[4] = "星期四";
		weekday[5] = "星期五";
		weekday[6] = "星期六";
		return weekday[d.getDay()];
	};

	//to show day of week in English
	function showDayOfWeekEng (d) {
		var weekday = new Array(7);
		weekday[0] = "Sunday";
		weekday[1] = "Monday";
		weekday[2] = "Tuesday";
		weekday[3] = "Wednesday";
		weekday[4] = "Thursday";
		weekday[5] = "Firday";
		weekday[6] = "Saturday";
		return weekday[d.getDay()];
	};

	//to show month of year
	function showMonthOfYear (d) {
		var month = new Array(12);
		var i = 0;
		while( i <= 11 )
		{
			month[i] = i + 1;
			++i;
		}
		return month[d.getMonth()];
	};
	var yearInput = document.getElementById("yearInput").value;
	var monthInput = document.getElementById("monthInput").value;
	if (yearInput == "" || monthInput == "") {
		if (yearInput == "") {
			document.getElementById("sYear").innerHTML = "";
		}
		if (monthInput == "") {
			document.getElementById("sMonth").innerHTML = " ";
		}
	} else if (yearInput < 2001 || yearInput > 2050 || monthInput < 1 || monthInput > 12) {
		if (yearInput < 2001 || yearInput > 2050) {
			document.getElementById("sYear").innerHTML = "请确定年份介于2001至2050  ";
		}
		if (monthInput < 1 || monthInput > 12) {
			document.getElementById("sMonth").innerHTML = "请确定月份介于1至12  ";
		}
	} else {
		d.setFullYear(yearInput, monthInput - 1);
	}
	
   
    return d.getFullYear() + "年" + showMonthOfYear(d) + "月";
}

function show_Year(d){
	var yearInput = document.getElementById("yearInput").value;
	if (yearInput == "") {
		if (yearInput == "") {
			document.getElementById("sYear").innerHTML = "";
		}
	} else if (yearInput < 2001 || yearInput > 2050) {
		if (yearInput < 2001 || yearInput > 2050) {
			document.getElementById("sYear").innerHTML = "请确定年份介于2001至2050  ";
		}		
	} else {
		d.setFullYear(yearInput);
	}
	
	return d.getFullYear();
}

function show_Month(d){
	var monthInput = document.getElementById("monthInput").value;
	if (monthInput == "") {		
		if (monthInput == "") {
			document.getElementById("sMonth").innerHTML = " ";
		}
	} else if (monthInput < 1 || monthInput > 12) {		
		if (monthInput < 1 || monthInput > 12) {
			document.getElementById("sMonth").innerHTML = "请确定月份介于1至12  ";
		}
	} else {
		d.setMonth(monthInput - 1);
	}
	
	return d.getMonth()+1;
}

function showCalendar(d) {
	// 数组LunarDaysOfMonth存入农历2001年到2050年每年中的月天数信息 
	// 农历每月只能是29或30天，一年用12(或13)个二进制位表示，从高到低，对应位为1表示30天，否则29天 
	var LunarDaysOfMonth = new Array
	(
		0xd4a8, 0xd4a0, 0xda50, 0x5aa8, 0x56a0, 0xaad8, 0x25d0, 0x92d0, 0xc958, 0xa950, // 2001-2010 
		0xb4a0, 0xb550, 0xb550, 0x55a8, 0x4ba0, 0xa5b0, 0x52b8, 0x52b0, 0xa930, 0x74a8, // 2011-2020 
		0x6aa0, 0xad50, 0x4da8, 0x4b60, 0x9570, 0xa4e0, 0xd260, 0xe930, 0xd530, 0x5aa0, // 2021-2030 
		0x6b50, 0x96d0, 0x4ae8, 0x4ad0, 0xa4d0, 0xd258, 0xd250, 0xd520, 0xdaa0, 0xb5a0, // 2031-2040 
		0x56d0, 0x4ad8, 0x49b0, 0xa4b8, 0xa4b0, 0xaa50, 0xb528, 0x6d20, 0xada0, 0x55b0  // 2041-2050 
	);

	// 数组LunarLeapYear存放农历2001年到2050年闰月的月份，如没有则为0，从高到低，每字节存两年 
	var LunarLeapYear = new Array
	(
		0x40, 0x02, 0x07, 0x00, 0x50, // 2001-2010 
		0x04, 0x09, 0x00, 0x60, 0x04, // 2011-2020 
		0x00, 0x20, 0x60, 0x05, 0x00, // 2021-2030 
		0x30, 0xb0, 0x06, 0x00, 0x50, // 2031-2040 
		0x02, 0x07, 0x00, 0x50, 0x03  // 2041-2050 
	);
	var yearInput = document.getElementById("yearInput").value;
	var monthInput = document.getElementById("monthInput").value;
	if (yearInput == "" || monthInput == "") {
	
	} else if (yearInput < 2001 || yearInput > 2050 || monthInput < 1 || monthInput > 12) {
		if (yearInput < 2001 || yearInput > 2050) {
			document.getElementById("sYear").innerHTML = "请确定年份介于2001至2050  ";
		}
		if (monthInput < 1 || monthInput > 12) {
			document.getElementById("sMonth").innerHTML = "请确定月份介于1至12  ";
		}
	} else {
		d.setFullYear(yearInput, monthInput - 1);
	}
	

	//to show first day of month
	function showFirstDayOfMonth(d) {
		var tempDate = new Date();
		tempDate.setFullYear(d.getFullYear(), d.getMonth(), 1);
		//返回的是0~6！！！！！
		return tempDate.getDay();
	};

	//to show total day of month in year
	function showTotalDayOfMonthInYear(year) {
		var day_m;
		//判断闰年和平年
		if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)) {
			day_m = Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
		}
		else {
			day_m = Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
		}
		//返回查询年份的各月天数数组，！！！！！！！！！注意下标从0开始！！！！！！！！！
		return day_m;
	};

	//to show total day of month
	function showTotalDayOfMonth(d) {
		var year = d.getFullYear();
		var day_m = showTotalDayOfMonthInYear(year);
		return day_m[d.getMonth()];
	};

	//to show id
	function showId(r, c) {
		var rcId = "r" + r + "c" + c;
		return rcId;
	};

	//to show month of year
	function showMonthOfYear(d) {
		var month = new Array(12);
		var i = 0;
		while( i <= 11 )
		{
			month[i] = i + 1;
			++i;
		}
		return month[d.getMonth()];
	};

	//query festival  固定日期的
	function showFestivalFixed(d) {
		//新历算的节假日
		var festivalDay1 = new Array(
			"1月1日", "3月8日", "3月12日", "4月1日", "5月1日",
			"6月1日", "7月1日", "8月1日", "9月10日", "10月1日",
			"10月31日", "12月24日", "12月25日"
			);
		var festival1 = new Array(
			"元旦", "妇女节", "植树节", "愚人节", "劳动节",
			"儿童节", "建党", "建军", "教师节", "国庆",
			"万圣节", "平安夜", "圣诞节"
			);
		//农历算的节日
		var festivalDay2 = new Array(
			"正月初一", "正月十五", "五月初五", "七月初七", "八月十五", "九月初九"
			);
		var festival2 = new Array(
			"春节", "元宵", "端午", "七夕", "中秋", "重阳节"
			);
		var str1 = "";  //新历节日
		var str2 = "";  //农历节日
		var day1 = showMonthOfYear(d) + "月" + d.getDate() + "日";  //新历日期
		var day2 = GetLunarDateStringPart(d);  //农历日期
		var i;
		for (i = 0; i < 13; ++i) {
			if (festivalDay1[i] == day1) {
				str1 = festival1[i];
			}
		}
		for (i = 0; i < 6; ++i) {
			if (festivalDay2[i] == day2) {
				str2 = festival2[i];
			}
		}

		//规则不明显的节日
		//母亲节：5月第2个周日
		//父亲节：6月第3个周日
		//感恩节：每年11月的第四个星期四
		var str3 = "";
		var day3 = showMonthOfYear(d);
		var firstDay = showFirstDayOfMonth(d);
		//母亲节
		if (day3 == 5) {
			if (firstDay == 0) {
				if (d.getDate() == 8) {
					str3 = "母亲节";
				}
			}
			else {
				if (d.getDate() == 7 - firstDay + 8) {
					str3 = "母亲节";
				}
			}
		}
		//父亲节
		if (day3 == 6) {
			if (firstDay == 0) {
				if (d.getDate() == 15) {
					str3 = "父亲节";
				}
			}
			else {
				if (d.getDate() == 7 - firstDay + 15) {
					str3 = "父亲节";
				}
			}
		}
		//感恩节
		if (day3 == 11) {
			if (firstDay <= 4) {
				if (d.getDate() == 7 - firstDay + 19) {
					str3 = "感恩节";
				}
			}
			else {
				if (d.getDate() == 7 - firstDay + 26) {
					str3 = "感恩节";
				}
			}
		}
		return str1 + " " + str2 + " " + str3;
	};

	//补上上个月的日期
	function showPre(d) {
		//补上上个月的日期
		//注意月份和星期都按0~某某数为准
		var first_c = showFirstDayOfMonth(d) + 1;   //当天所在月头一天星期几的标号
		var preD = new Date();
		preD.setFullYear(d.getFullYear(), d.getMonth(), d.getDate());
		preD.setMonth(preD.getMonth() - 1);
		var maxD = showTotalDayOfMonth(preD);
		var tempC = first_c - 1;
		while (tempC > 0) {
			var preRcId = showId(1, tempC);
			var preNode = document.getElementById(preRcId);
			preNode.style.color = "grey";
			var prePriDayPos = document.getElementById(preRcId).firstChild;
			prePriDayPos.innerHTML = maxD;
			preD.setDate(maxD);
			var str = GetLunarDateStringPart(preD);
			var lunar = document.getElementById("p" + preRcId);
			lunar.innerHTML = str;
			var festival = showFestivalFixed(preD);
			var fes = document.getElementById("d" + preRcId);
			fes.innerHTML = festival;
			tempC = tempC - 1;
			maxD = maxD - 1;
		}
	};

	//get leap month
	function GetLeapMonth(iLunarYear) {
		var Leap = LunarLeapYear[(iLunarYear - 2001) >> 1];
		return (((iLunarYear - 2001) & 1) == 0) ? (Leap >> 4) : (Leap & 0x0f);
	};

	// 返回农历iLunarYer年iLunarMonth月的天数，结果是一个长整数
	// 如果iLunarMonth不是闰月， 高字为0，低字为该月的天数
	// 如果iLunarMonth是闰月， 高字为后一个月的天数，低字为前一个月的天数
	function LunarMonthDays(iLunarYear, iLunarMonth) {
		var High;
		var Low;
		var Bit;

		High = 0;
		Low = 29;
		Bit = 16 - iLunarMonth;
		if ((iLunarMonth > GetLeapMonth(iLunarYear)) && (GetLeapMonth(iLunarYear) > 0)) Bit--;
		if ((LunarDaysOfMonth[iLunarYear - 2001] & (1 << Bit)) > 0) Low++;
		if (iLunarMonth == GetLeapMonth(iLunarYear)) {
			High = ((LunarDaysOfMonth[iLunarYear - 2001] & (1 << (Bit - 1))) > 0) ? 30 : 29;
		}

		return Low + (High << 16);
	};

	//返回农历iLunarYear年的总天数
	function LunarYearDays(iLunarYear) {
		var Days;
		var tmp;

		Days = 0;
		for (var i = 1; i <= 12; i++) {
			tmp = LunarMonthDays(iLunarYear, i);
			Days = Days + ((tmp >> 16) & 0xffff); //取高位 
			Days = Days + (tmp & 0xffff); //取低位 
		}

		return Days;
	};

	// 将农历iLunarYear年格式化成天干地支记年法表示的字符串
	function FormatLunarYear(iLunarYear) {
		var szText1 = new String("甲乙丙丁戊己庚辛壬癸");
		var szText2 = new String("子丑寅卯辰巳午未申酉戌亥");
		var strYear;

		strYear = szText1.substr((iLunarYear - 4) % 10, 1);
		strYear = strYear + szText2.substr((iLunarYear - 4) % 12, 1);

		return strYear + "年";
	};

	// 将农历iLunarMonth月格式化成农历表示的字符串
	function FormatLunarMonth(iLunarMonth) {
		var szText = new String("正二三四五六七八九十");
		var strMonth;

		if (iLunarMonth <= 10) {
			strMonth = szText.substr(iLunarMonth - 1, 1);
		}
		else if (iLunarMonth == 11) strMonth = "十一";
		else strMonth = "十二";

		return strMonth + "月";
	};

	// 将农历iLunarDay日格式化成农历表示的字符串
	function FormatLunarDay(iLunarDay) {
		var szText1 = new String("初十廿三");
		var szText2 = new String("一二三四五六七八九十");
		var strDay;
		if ((iLunarDay != 20) && (iLunarDay != 30)) {
			strDay = szText1.substr((iLunarDay - 1) / 10, 1) + szText2.substr((iLunarDay - 1) % 10, 1);
		}
		else if (iLunarDay != 20) {
			strDay = szText1.substr(iLunarDay / 10, 1) + "十";
		}
		else {
			strDay = "二十";
		}

		return strDay;
	};

	// 将公历日期转换为农历日期，返回农历表示的字符串
	function GetLunarDateString(SolarDate) {
	  
		var tmp;
		var iLunarYear;
		var iLunarMonth;
		var iLunarDay;
		var Leap = false;
		var MinMilli = 1000 * 60;
		var HrMilli = MinMilli * 60;
		var DyMilli = HrMilli * 24;

		// 从2001年1月1日算起，给定的公历日期已经过去的天数
		// 11323是1970年1月1日到2001年1月1日之间的天数，因为Date是从1970年1月1日作为起点的
		var iSpanDays = Math.round(SolarDate.getTime() / DyMilli) - 11323;

		// 公历2001年1月24日为农历2001年正月初一，差23天
		if (iSpanDays < 23) {
			iYear = 2000;
			iLunarMonth = 12;
			iLunarDay = iSpanDays + 7;
		}
		else {
			// 从农历2001年正月初一算起 
			iSpanDays = iSpanDays - 23;
			iLunarYear = 2001;
			iLunarMonth = 1;
			iLunarDay = 1;

			// 计算农历年 
			tmp = LunarYearDays(iLunarYear);
			while (iSpanDays >= tmp) {
				iSpanDays -= tmp;
				iLunarYear++;
				tmp = LunarYearDays(iLunarYear);
			}

			// 计算农历月 
			tmp = LunarMonthDays(iLunarYear, iLunarMonth) & 0xffff; //取低字
			while (iSpanDays >= tmp) {
				iSpanDays -= tmp;
				if (iLunarMonth == GetLeapMonth(iLunarYear))  // 该年该月闰月
				{
					tmp = LunarMonthDays(iLunarYear, iLunarMonth) >> 16; //取高字
					if (iSpanDays < tmp) {
						Leap = (tmp > 0) ? true : false;  // 闰月的后个月？
						break;
					}
					iSpanDays = iSpanDays - tmp;
				}

				iLunarMonth++;
				tmp = LunarMonthDays(iLunarYear, iLunarMonth) & 0xffff; //取低字
			}

			// 计算农历日 
			iLunarDay += iSpanDays;
		}
		if (SolarDate.getHours() > 19) {
			return FormatLunarYear(iLunarYear) + (Leap ? "闰" : "") + FormatLunarMonth(iLunarMonth) + FormatLunarDay(iLunarDay - 1);
		} else {
			return FormatLunarYear(iLunarYear) + (Leap ? "闰" : "") + FormatLunarMonth(iLunarMonth) + FormatLunarDay(iLunarDay);
		}
	};

	// 将公历日期转换为农历日期，返回农历表示的字符串
	function GetLunarDateStringPart(SolarDate) {
	   
		var tmp;
		var iLunarYear;
		var iLunarMonth;
		var iLunarDay;
		var Leap = false;
		var MinMilli = 1000 * 60;
		var HrMilli = MinMilli * 60;
		var DyMilli = HrMilli * 24;

		// 从2001年1月1日算起，给定的公历日期已经过去的天数
		// 11323是1970年1月1日到2001年1月1日之间的天数，因为Date是从1970年1月1日作为起点的
		var iSpanDays = Math.round(SolarDate.getTime() / DyMilli) - 11323;

		// 公历2001年1月24日为农历2001年正月初一，差23天
		if (iSpanDays < 23) {
			iLunarYear = 2000;
			iLunarMonth = 12;
			iLunarDay = iSpanDays + 7;
		}
		else {
			// 从农历2001年正月初一算起 
			iSpanDays = iSpanDays - 23;
			iLunarYear = 2001;
			iLunarMonth = 1;
			iLunarDay = 1;

			// 计算农历年 
			tmp = LunarYearDays(iLunarYear);
			while (iSpanDays >= tmp) {
				iSpanDays -= tmp;
				iLunarYear++;
				tmp = LunarYearDays(iLunarYear);
			}

			// 计算农历月 
			tmp = LunarMonthDays(iLunarYear, iLunarMonth) & 0xffff; //取低字
			while (iSpanDays >= tmp) {
				iSpanDays -= tmp;
				if (iLunarMonth == GetLeapMonth(iLunarYear))  // 该年该月闰月
				{
					tmp = LunarMonthDays(iLunarYear, iLunarMonth) >> 16; //取高字
					if (iSpanDays < tmp) {
						Leap = (tmp > 0) ? true : false;  // 闰月的后个月？
						break;
					}
					iSpanDays = iSpanDays - tmp;
				}

				iLunarMonth++;
				tmp = LunarMonthDays(iLunarYear, iLunarMonth) & 0xffff; //取低字
			}

			// 计算农历日 
			iLunarDay += iSpanDays;
		}
		if (SolarDate.getHours() > 19) {
			return (Leap ? "闰" : "") + FormatLunarMonth(iLunarMonth) + FormatLunarDay(iLunarDay - 1);
		} else {
			return (Leap ? "闰" : "") + FormatLunarMonth(iLunarMonth) + FormatLunarDay(iLunarDay);
		}
	};

	var first_c = showFirstDayOfMonth(d) + 1;   //当天所在月头一天星期几的标号
	var total_day = showTotalDayOfMonth(d);    //当天所在月总共天数
	var r = 1;      //行标
	var c = first_c;   //列标
	
	var headlineDay = new Date();
	var nodeHeadline = document.getElementById("headline");
	nodeHeadline.innerHTML = GetLunarDateString(headlineDay);

	//补上上个月的日期
	//注意月份和星期都按0~某某数为准
	showPre(d);
 
	//打印当天所在月
	var d1 = new Date();
	d1.setFullYear(d.getFullYear(), d.getMonth(), d.getDate());
	var i;       //计数器
	var supPos = first_c;   //用来判断是否换行
	var curRcId = "what";     //当天的坐标
	var iCurDay = new Date();  //今天!!
	var curDate = iCurDay.getDate();    //当天所在月的第几天
	for(i=1; i<=total_day; ++i, ++supPos)
	{
		d1.setDate(i);
		var rcId = showId(r, c);
		var node = document.getElementById(rcId);
		var priDayPos = document.getElementById("a"+rcId);
		priDayPos.innerHTML = i;
		
		var lunar = document.getElementById("p" + rcId);
		var str = GetLunarDateStringPart(d1);
		lunar.innerHTML = str;
		var festival = showFestivalFixed(d1);
		var fes = document.getElementById("d" + rcId);
		fes.innerHTML = festival;
		node.style.color = "black";
		node.style.textDecoration = "none";
		priDayPos.style.fontSize = "20px";
		//检查是否是当天 
		if (i == curDate && iCurDay.getMonth() == d.getMonth() && iCurDay.getFullYear() == d.getFullYear() ) {
			curRcId = rcId;
			//对当天进行特殊标记
			var today = document.getElementById(curRcId);
			today.style.color = "red";
			priDayPos.style.fontSize = "30px";
			today.style.textDecoration = "underline";
		}

		if(supPos % 7 == 0){
			r = r + 1;
		}
		if (c == 7) {
			c = 0;
		}
		c = c + 1;
	}
	
	//补充后面的日期
	var k = 1;
	var d2 = new Date();
	d2.setFullYear(d.getFullYear());
	d2.setMonth(d.getMonth() + 1);
	d2.setDate(1);
	while (supPos <= 42) {
		var nextRcId = showId(r, c);
		var nextNode = document.getElementById(nextRcId);
		nextNode.style.color = "grey";
		var nextPriDayPos = document.getElementById(nextRcId).firstChild;
		nextPriDayPos.innerHTML = k;
		var lunar = document.getElementById("p" + nextRcId);               
		var str = GetLunarDateStringPart(d2);
		lunar.innerHTML = str;
		
		var festivalN = showFestivalFixed(d2);
		var fesN = document.getElementById("d" + nextRcId);
		fesN.innerHTML = festivalN;
		d2.setDate(d2.getDate() + 1);
		if (supPos % 7 == 0) {
			r = r + 1;
		}
		if (c == 7) {
			c = 0;
		}
		c = c + 1;
		supPos = supPos + 1;
		k = k + 1;
	}
}

function showWeek(d) {
	// 数组LunarDaysOfMonth存入农历2001年到2050年每年中的月天数信息 
	// 农历每月只能是29或30天，一年用12(或13)个二进制位表示，从高到低，对应位为1表示30天，否则29天 
	var LunarDaysOfMonth = new Array
	(
		0xd4a8, 0xd4a0, 0xda50, 0x5aa8, 0x56a0, 0xaad8, 0x25d0, 0x92d0, 0xc958, 0xa950, // 2001-2010 
		0xb4a0, 0xb550, 0xb550, 0x55a8, 0x4ba0, 0xa5b0, 0x52b8, 0x52b0, 0xa930, 0x74a8, // 2011-2020 
		0x6aa0, 0xad50, 0x4da8, 0x4b60, 0x9570, 0xa4e0, 0xd260, 0xe930, 0xd530, 0x5aa0, // 2021-2030 
		0x6b50, 0x96d0, 0x4ae8, 0x4ad0, 0xa4d0, 0xd258, 0xd250, 0xd520, 0xdaa0, 0xb5a0, // 2031-2040 
		0x56d0, 0x4ad8, 0x49b0, 0xa4b8, 0xa4b0, 0xaa50, 0xb528, 0x6d20, 0xada0, 0x55b0  // 2041-2050 
	);

	// 数组LunarLeapYear存放农历2001年到2050年闰月的月份，如没有则为0，从高到低，每字节存两年 
	var LunarLeapYear = new Array
	(
		0x40, 0x02, 0x07, 0x00, 0x50, // 2001-2010 
		0x04, 0x09, 0x00, 0x60, 0x04, // 2011-2020 
		0x00, 0x20, 0x60, 0x05, 0x00, // 2021-2030 
		0x30, 0xb0, 0x06, 0x00, 0x50, // 2031-2040 
		0x02, 0x07, 0x00, 0x50, 0x03  // 2041-2050 
	);

	//to show first day of month
	function showFirstDayOfMonth(d) {
		var tempDate = new Date();
		tempDate.setFullYear(d.getFullYear(), d.getMonth(), 1);
		//返回的是0~6！！！！！
		return tempDate.getDay();
	};

	//to show month of year
	function showMonthOfYear(d) {
		var month = new Array(12);
		var i = 0;
		while (i <= 11) {
			month[i] = i + 1;
			++i;
		}
		return month[d.getMonth()];
	};

	//query festival  固定日期的
	function showFestivalFixed(d) {
		//新历算的节假日
		var festivalDay1 = new Array(
			"1月1日", "3月8日", "3月12日", "4月1日", "5月1日",
			"6月1日", "7月1日", "8月1日", "9月10日", "10月1日",
			"10月31日", "12月24日", "12月25日"
			);
		var festival1 = new Array(
			"元旦", "妇女节", "植树节", "愚人节", "劳动节",
			"儿童节", "建党", "建军", "教师节", "国庆",
			"万圣节", "平安夜", "圣诞节"
			);
		//农历算的节日
		var festivalDay2 = new Array(
			"正月初一", "正月十五", "五月初五", "七月初七", "八月十五", "九月初九"
			);
		var festival2 = new Array(
			"春节", "元宵", "端午", "七夕", "中秋", "重阳节"
			);
		var str1 = "";  //新历节日
		var str2 = "";  //农历节日
		var day1 = showMonthOfYear(d) + "月" + d.getDate() + "日";  //新历日期
		var day2 = GetLunarDateStringPart(d);  //农历日期
		var i;
		for (i = 0; i < 13; ++i) {
			if (festivalDay1[i] == day1) {
				str1 = festival1[i];
			}
		}
		for (i = 0; i < 6; ++i) {
			if (festivalDay2[i] == day2) {
				str2 = festival2[i];
			}
		}

		//规则不明显的节日
		//母亲节：5月第2个周日
		//父亲节：6月第3个周日
		//感恩节：每年11月的第四个星期四
		var str3 = "";
		var day3 = showMonthOfYear(d);
		var firstDay = showFirstDayOfMonth(d);
		//母亲节
		if (day3 == 5) {
			if (firstDay == 0) {
				if (d.getDate() == 8) {
					str3 = "母亲节";
				}
			}
			else {
				if (d.getDate() == 7 - firstDay + 8) {
					str3 = "母亲节";
				}
			}
		}
		//父亲节
		if (day3 == 6) {
			if (firstDay == 0) {
				if (d.getDate() == 15) {
					str3 = "父亲节";
				}
			}
			else {
				if (d.getDate() == 7 - firstDay + 15) {
					str3 = "父亲节";
				}
			}
		}
		//感恩节
		if (day3 == 11) {
			if (firstDay <= 4) {
				if (d.getDate() == 7 - firstDay + 19) {
					str3 = "感恩节";
				}
			}
			else {
				if (d.getDate() == 7 - firstDay + 26) {
					str3 = "感恩节";
				}
			}
		}
		return str1 + " " + str2 + " " + str3;
	};

	//to show day of week in number 1~7
	function showDayOfWeekNum(d) {
		var weekday = new Array(7);
		weekday[0] = "7";
		weekday[1] = "1";
		weekday[2] = "2";
		weekday[3] = "3";
		weekday[4] = "4";
		weekday[5] = "5";
		weekday[6] = "6";
		return weekday[d.getDay()];
	};

	//to show day of week in English
	function showDayOfWeekEng(d) {
		var weekday = new Array(7);
		weekday[0] = "Sunday";
		weekday[1] = "Monday";
		weekday[2] = "Tuesday";
		weekday[3] = "Wednesday";
		weekday[4] = "Thursday";
		weekday[5] = "Firday";
		weekday[6] = "Saturday";
		return weekday[d.getDay()];
	};

	//to show day of week in zhongwen
	function showDayOfWeek(d) {
		var weekday = new Array(7);
		weekday[0] = "星期日";
		weekday[1] = "星期一";
		weekday[2] = "星期二";
		weekday[3] = "星期三";
		weekday[4] = "星期四";
		weekday[5] = "星期五";
		weekday[6] = "星期六";
		return weekday[d.getDay()];
	};

	//to show month of year
	function showMonthOfYear(d) {
		var month = new Array(12);
		var i = 0;
		while (i <= 11) {
			month[i] = i + 1;
			++i;
		}
		return month[d.getMonth()];
	};

	function showWeekId(x, y) {
		var xyId = "x" + x + "y" + y;
		return xyId;
	};

	//get leap month
	function GetLeapMonth(iLunarYear) {
		var Leap = LunarLeapYear[(iLunarYear - 2001) >> 1];
		return (((iLunarYear - 2001) & 1) == 0) ? (Leap >> 4) : (Leap & 0x0f);
	};

	// 返回农历iLunarYer年iLunarMonth月的天数，结果是一个长整数
	// 如果iLunarMonth不是闰月， 高字为0，低字为该月的天数
	// 如果iLunarMonth是闰月， 高字为后一个月的天数，低字为前一个月的天数
	function LunarMonthDays(iLunarYear, iLunarMonth) {
		var High;
		var Low;
		var Bit;

		High = 0;
		Low = 29;
		Bit = 16 - iLunarMonth;
		if ((iLunarMonth > GetLeapMonth(iLunarYear)) && (GetLeapMonth(iLunarYear) > 0)) Bit--;
		if ((LunarDaysOfMonth[iLunarYear - 2001] & (1 << Bit)) > 0) Low++;
		if (iLunarMonth == GetLeapMonth(iLunarYear)) {
			High = ((LunarDaysOfMonth[iLunarYear - 2001] & (1 << (Bit - 1))) > 0) ? 30 : 29;
		}

		return Low + (High << 16);
	};

	//返回农历iLunarYear年的总天数
	function LunarYearDays(iLunarYear) {
		var Days;
		var tmp;

		Days = 0;
		for (var i = 1; i <= 12; i++) {
			tmp = LunarMonthDays(iLunarYear, i);
			Days = Days + ((tmp >> 16) & 0xffff); //取高位 
			Days = Days + (tmp & 0xffff); //取低位 
		}

		return Days;
	};

	// 将农历iLunarYear年格式化成天干地支记年法表示的字符串
	function FormatLunarYear(iLunarYear) {
		var szText1 = new String("甲乙丙丁戊己庚辛壬癸");
		var szText2 = new String("子丑寅卯辰巳午未申酉戌亥");
		var strYear;

		strYear = szText1.substr((iLunarYear - 4) % 10, 1);
		strYear = strYear + szText2.substr((iLunarYear - 4) % 12, 1);

		return strYear + "年";
	};

	// 将农历iLunarMonth月格式化成农历表示的字符串
	function FormatLunarMonth(iLunarMonth) {
		var szText = new String("正二三四五六七八九十");
		var strMonth;

		if (iLunarMonth <= 10) {
			strMonth = szText.substr(iLunarMonth - 1, 1);
		}
		else if (iLunarMonth == 11) strMonth = "十一";
		else strMonth = "十二";

		return strMonth + "月";
	};

	// 将农历iLunarDay日格式化成农历表示的字符串
	function FormatLunarDay(iLunarDay) {
		var szText1 = new String("初十廿三");
		var szText2 = new String("一二三四五六七八九十");
		var strDay;
		if ((iLunarDay != 20) && (iLunarDay != 30)) {
			strDay = szText1.substr((iLunarDay - 1) / 10, 1) + szText2.substr((iLunarDay - 1) % 10, 1);
		}
		else if (iLunarDay != 20) {
			strDay = szText1.substr(iLunarDay / 10, 1) + "十";
		}
		else {
			strDay = "二十";
		}

		return strDay;
	};

	// 将公历日期转换为农历日期，返回农历表示的字符串
	function GetLunarDateString(SolarDate) {

		var tmp;
		var iLunarYear;
		var iLunarMonth;
		var iLunarDay;
		var Leap = false;
		var MinMilli = 1000 * 60;
		var HrMilli = MinMilli * 60;
		var DyMilli = HrMilli * 24;

		// 从2001年1月1日算起，给定的公历日期已经过去的天数
		// 11323是1970年1月1日到2001年1月1日之间的天数，因为Date是从1970年1月1日作为起点的
		var iSpanDays = Math.round(SolarDate.getTime() / DyMilli) - 11323;

		// 公历2001年1月24日为农历2001年正月初一，差23天
		if (iSpanDays < 23) {
			iYear = 2000;
			iLunarMonth = 12;
			iLunarDay = iSpanDays + 7;
		}
		else {
			// 从农历2001年正月初一算起 
			iSpanDays = iSpanDays - 23;
			iLunarYear = 2001;
			iLunarMonth = 1;
			iLunarDay = 1;

			// 计算农历年 
			tmp = LunarYearDays(iLunarYear);
			while (iSpanDays >= tmp) {
				iSpanDays -= tmp;
				iLunarYear++;
				tmp = LunarYearDays(iLunarYear);
			}

			// 计算农历月 
			tmp = LunarMonthDays(iLunarYear, iLunarMonth) & 0xffff; //取低字
			while (iSpanDays >= tmp) {
				iSpanDays -= tmp;
				if (iLunarMonth == GetLeapMonth(iLunarYear))  // 该年该月闰月
				{
					tmp = LunarMonthDays(iLunarYear, iLunarMonth) >> 16; //取高字
					if (iSpanDays < tmp) {
						Leap = (tmp > 0) ? true : false;  // 闰月的后个月？
						break;
					}
					iSpanDays = iSpanDays - tmp;
				}

				iLunarMonth++;
				tmp = LunarMonthDays(iLunarYear, iLunarMonth) & 0xffff; //取低字
			}

			// 计算农历日 
			iLunarDay += iSpanDays;
		}

		return FormatLunarYear(iLunarYear) + (Leap ? "闰" : "") + FormatLunarMonth(iLunarMonth) + FormatLunarDay(iLunarDay);
	};

	// 将公历日期转换为农历日期，返回农历表示的字符串
	function GetLunarDateStringPart(SolarDate) {

		var tmp;
		var iLunarYear;
		var iLunarMonth;
		var iLunarDay;
		var Leap = false;
		var MinMilli = 1000 * 60;
		var HrMilli = MinMilli * 60;
		var DyMilli = HrMilli * 24;

		// 从2001年1月1日算起，给定的公历日期已经过去的天数
		// 11323是1970年1月1日到2001年1月1日之间的天数，因为Date是从1970年1月1日作为起点的
		var iSpanDays = Math.round(SolarDate.getTime() / DyMilli) - 11323;

		// 公历2001年1月24日为农历2001年正月初一，差23天
		if (iSpanDays < 23) {
			iYear = 2000;
			iLunarMonth = 12;
			iLunarDay = iSpanDays + 7;
		}
		else {
			// 从农历2001年正月初一算起 
			iSpanDays = iSpanDays - 23;
			iLunarYear = 2001;
			iLunarMonth = 1;
			iLunarDay = 1;

			// 计算农历年 
			tmp = LunarYearDays(iLunarYear);
			while (iSpanDays >= tmp) {
				iSpanDays -= tmp;
				iLunarYear++;
				tmp = LunarYearDays(iLunarYear);
			}

			// 计算农历月 
			tmp = LunarMonthDays(iLunarYear, iLunarMonth) & 0xffff; //取低字
			while (iSpanDays >= tmp) {
				iSpanDays -= tmp;
				if (iLunarMonth == GetLeapMonth(iLunarYear))  // 该年该月闰月
				{
					tmp = LunarMonthDays(iLunarYear, iLunarMonth) >> 16; //取高字
					if (iSpanDays < tmp) {
						Leap = (tmp > 0) ? true : false;  // 闰月的后个月？
						break;
					}
					iSpanDays = iSpanDays - tmp;
				}

				iLunarMonth++;
				tmp = LunarMonthDays(iLunarYear, iLunarMonth) & 0xffff; //取低字
			}

			// 计算农历日 
			iLunarDay += iSpanDays;
		}

		return FormatLunarMonth(iLunarMonth) + FormatLunarDay(iLunarDay);
	};

	//to show one day in week
	function showOneDayInWeek(d) {
		var curDay = d.getDay();   //从 Date 对象返回一周中的某一天 (0 ~ 6)
		var curDayZh = showDayOfWeek(d);
		var curMonth = showMonthOfYear(d);
		var curDate = d.getDate();
		var curId1 = showWeekId(curDay, 1);
		var curElement1 = document.getElementById(curId1);
		curElement1.innerHTML = d.getFullYear() + "年";
		var curId2 = showWeekId(curDay, 2);
		var curElement2 = document.getElementById(curId2);
		curElement2.innerHTML = curMonth + "月" + curDate + "日";
		var curId3 = showWeekId(curDay, 3);
		var curElement3 = document.getElementById(curId3);
		curElement3.innerHTML = curDayZh;
		var curId4 = showWeekId(curDay, 4);
		var curElement4 = document.getElementById(curId4);
		curElement4.innerHTML = GetLunarDateStringPart(d);
		var festival = showFestivalFixed(d);
		var fes = document.getElementById("d" + curId1);
		fes.innerHTML = festival;
	};

	var flag = showDayOfWeekNum(d);
	var curId = showDayOfWeekEng(d);
	var curDay = document.getElementById(curId);
	curDay.style.backgroundColor = "yellow";

	var firstDay = new Date();
	firstDay.setFullYear(d.getFullYear(), d.getMonth(), d.getDate());
	firstDay.setDate(firstDay.getDate() - flag + 1);
	var i;
	for (i = 1; i <= 7; ++i) {
		showOneDayInWeek(firstDay);
		firstDay.setDate(firstDay.getDate() + 1);
	}
}



